home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 026-050 / scopedisk46 / flip / flip.macros < prev    next >
Text File  |  1995-03-18  |  4KB  |  206 lines

  1. amiref    macro
  2.     xref _LVO\1
  3.     endm
  4.  
  5. libcall macro    ;library, routine
  6.     move.l \1,a6
  7.     jsr _LVO\2(A6)
  8.     endm
  9.  
  10. execlib macro    ;routine
  11.     libcall execbase,\1
  12.     endm
  13.  
  14. doslib macro    ;routine
  15.     libcall dosbase,\1
  16.     endm
  17.  
  18. gfxlib macro    ;routine[,*rastport]
  19.     ifnc '\2',''
  20.     move.l \2,a1
  21.     endc
  22.     libcall gfxbase,\1
  23.     endm
  24.  
  25. intlib macro    ;routine
  26.     libcall intbase,\1
  27.     endm
  28.  
  29. oplib macro ; library name,pointer to base address
  30.     move.l    execbase,a6
  31.     lea    \1,a1        ;library name
  32.     move.l    #0,d0
  33.     execlib    OpenLibrary
  34.     move.l    d0,\2        ;save pointer to library base address
  35.     endm
  36.  
  37. clolib macro ; library base address - must test if open before call
  38.     movea.l    \1,a1
  39.     execlib    CloseLibrary
  40.     endm
  41.  
  42. evenpc macro            ;used to word-align the program counter
  43.     ds.w 0
  44.     endm
  45.  
  46. zero macro
  47.     moveq #0,\1
  48.     endm
  49.  
  50. zera macro
  51.     suba.l \1,\1
  52.     endm
  53.  
  54. pushreg macro    ;register
  55.     movem.l \1,-(sp)
  56.     endm
  57.  
  58. pullreg macro
  59.     movem.l (sp)+,\1
  60.     endm
  61.  
  62. pause macro        ;#secs
  63.     move.l    \1,d1
  64.     zero    d0
  65.     move.w    #TICKS_PER_SECOND,d0
  66.     mulu    d0,d1
  67.     doslib    Delay
  68.     endm
  69.  
  70. getmem macro        ;(#)size in bytes,(#)type,*memblock
  71.     move.l    \1,d0
  72.     move.l    \2,d1
  73.     execlib    AllocMem
  74.     move.l    d0,\3
  75.     endm
  76.  
  77. byemem macro        ;(#)size in bytes,*memblock
  78.     move.l    \1,d0
  79.     ifnc    '\2',''
  80.     move.l    \2,a1
  81.     endc
  82.     execlib    FreeMem
  83.     endm
  84.  
  85. MakeTask macro        ;stacksize,*stack,*task,*name,*codeseg
  86.  
  87.     move.l    \1,d0        ;this rounds the stack size to the
  88.     addq.l    #3,d0        ;nearest long word
  89.     move.l    #$FFFFFFFC,d1
  90.     and.l    d1,d0
  91.     move.l    d0,\1
  92.  
  93.     move.l    #MEMF_CLEAR,d1    ;allocate mem for stack (not public)
  94.     execlib    AllocMem
  95.     move.l    d0,\2
  96.     beq    1$
  97.  
  98.     getmem    #TC_SIZE,#MEMF_CLEAR!MEMF_PUBLIC,\3    ;get mem for
  99.     beq    1$                    ;task control block
  100.  
  101.     move.l    \3,a0            ;task addr in a0
  102.     move.l    \2,a1            ;stack addr in a1
  103.     move.l    a1,TC_SPLOWER(a0)    ;put stack addr in task struct
  104.  
  105.     move.l    \1,d0            ;stacksize in d0
  106.     add.l    a1,d0            ;add stackaddr to it to get to upper
  107.     move.l    d0,TC_SPUPPER(a0)    ;put this value in task struct
  108.     move.l    d0,TC_SPREG(a0)        ;set the stack pointer to the top
  109.  
  110.     
  111.     move.b    #NT_TASK,LN_TYPE(a0)    ;set type in node struct
  112.     lea    \4,a1
  113.     move.l    a1,LN_NAME(a0)        ;load the task name into struct
  114.  
  115.     pushreg    a2-a3
  116.     move.l    \3,a1
  117.     lea    \5,a2
  118.     zera    a3
  119.     execlib    AddTask            ;returns nothing,hope all goes well
  120.     pullreg    a2-a3
  121. 1$
  122.     endm
  123. ;************************************************************************
  124. ByeTask    macro        ;stacksize,*stack,*task
  125.  
  126.     move.l    \3,d0
  127.     beq.s    1$
  128.     move.l    \3,a1
  129.     execlib    RemTask        ;remove the task
  130.     byemem    #TC_SIZE,\3    ;get back tcb memory
  131. 1$
  132.     move.l    \2,d0        ;get back the stack mem
  133.     beq.s    2$
  134.     byemem    \1,\2
  135. 2$
  136.     endm
  137. ;************************************************************************
  138. CreatePort macro        ;sigbit,*port,*name,*task - priority always zero
  139.  
  140.     zero    d0
  141.     move.b    #-1,d0
  142.     execlib    AllocSignal    ;get signal for the port
  143.     move.b    d0,\1
  144.     beq.s    1$
  145.  
  146.     zero    d0
  147.     getmem    #MP_SIZE,#MEMF_CLEAR!MEMF_PUBLIC,\2    ;get mem for
  148.     beq.s    1$                    ;port structure
  149.  
  150.     move.l    \2,a0
  151.     lea    \3,a1
  152.     move.l    a1,LN_NAME(a0)        ;load port name into port struct
  153.     move.b    #NT_MSGPORT,LN_TYPE(a0)    ;load type into the node struct
  154.  
  155.     move.b    #PA_SIGNAL,MP_FLAGS(a0)    ;we want a signal
  156.     move.b    \1,MP_SIGBIT(a0)    ;give it the signal bit we just got
  157.     move.l    \4,MP_SIGTASK(a0)    ;tell it which task to signal
  158.  
  159.     move.l    \2,a1
  160.     execlib    AddPort        ;hope all goes well
  161. 1$
  162.     endm
  163. ;************************************************************************
  164. DeletePort macro    ;*port,sigbit
  165.  
  166.     move.l    \1,d0
  167.     beq.s    1$
  168.     move.l    \1,a1
  169.     execlib    RemPort        ;remove the port
  170.     byemem    #MP_SIZE,\1    ;recover the memory for the port struct
  171. 1$
  172.     zero    d0
  173.     move.b    \2,d0
  174.     beq.s    2$
  175.     execlib    FreeSignal    ;give back the signal we allocated for
  176. 2$                ;this port
  177.     endm
  178. ;************************************************************************
  179. opencon macro            ;*console_spec_str,*fhandle(bcpl)
  180.     lea    \1,a0
  181.     move.l    a0,d1
  182.     pushreg    d2
  183.     move.l    #MODE_NEWFILE,d2
  184.     doslib    Open
  185.     move.l    d0,\2
  186.     pullreg    d2
  187.     tst.l    d0
  188.     beq    getevent
  189.     endm
  190. ;****************************************************************************
  191. closecon macro            ;*fhandle(BCPL)
  192.     move.l    \1,d1
  193.     doslib    Close
  194.     move.l    #0,\1
  195.     endm
  196. ;***************************************************************************
  197. conout macro            ;*fh,*bufbegin,*bufend
  198.     move.l    \1,d1
  199.     pushreg    d2-d3
  200.     move.l    #\2,d2
  201.     move.l    #\3-\2,d3
  202.     doslib    Write
  203.     pullreg    d2-d3
  204.     endm
  205. ;**************************************************************************
  206.